package com.runen.wnhz.runen.ui.activity.dataservice;

import android.provider.ContactsContract;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.common.utils.ACacheUtlis;
import com.runen.wnhz.runen.data.entity.BaseEntity;
import com.runen.wnhz.runen.data.entity.ShopDetail;
import com.runen.wnhz.runen.data.entity.UserBean;
import com.runen.wnhz.runen.di.component.ApplicationComponent;
import com.runen.wnhz.runen.di.component.DaggerPublicmComponent;
import com.runen.wnhz.runen.di.module.PublicmModule;
import com.runen.wnhz.runen.presenter.Contart.PublicmContart;
import com.runen.wnhz.runen.presenter.iPresenter.IPublicmDetailsPresenter;
import com.runen.wnhz.runen.ui.activity.BaseActivity;
import com.runen.wnhz.runen.ui.adapter.puadapter.ShopListAdapter;
import com.runen.wnhz.runen.widget.TitleBuilder;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018-04-26.
 * 数据服务跳转详情页面  只做显示就行，时间点击事件 其他不做操作
 */

public class DataSerciceDetails extends BaseActivity<IPublicmDetailsPresenter> implements PublicmContart.DetailsView {
    public static final String SHOP_ID = "shop_id";
    public static final String SHOPTYPE_ID = "type_id";
    public static final String SDATE = "sdate";
    public static final String EDATE = "edate";
    private String sDate;
    private String eDate;
    private String shopId;
    private String shopTypeId;
    /*调转过来塞值*/
    @BindView(R.id.details_img)
    public ImageView mDetails_img;
    @BindView(R.id.tv_shop_name)
    public TextView mShopName;
    UserBean reqeustUser;
    @BindView(R.id.rv_shop_detail)
    public RecyclerView mShopList;
    private List<String> mShopDetailList;
    private ShopListAdapter mAdapter;


    @Override
    protected int getLayoutView() {
        return R.layout.activity_datasercicedetails;
    }

    @Override
    protected void onTitleClickListen(TitleBuilder.TitleButton clicked) {
        switch (clicked) {
            case LEFT:
                this.finish();
                break;
            case MIDDLE:
                break;
            case RIGHT:
                break;
            default:
                break;
        }
    }

    @Override
    public void initPresente() {
        mPresenter.getShopDetail();
        //设置adapter
        initAdapter();
    }

    private void initAdapter() {
        mAdapter = new ShopListAdapter(mShopDetailList);
        mShopList.setLayoutManager(new LinearLayoutManager(this));
        mShopList.setAdapter(mAdapter);
    }

    @Override
    protected void initStart() {
        reqeustUser = ACacheUtlis.getInstance().getReqeustUser(this);
        sDate = getIntent().getStringExtra(DataSerciceDetails.SDATE);
        eDate = getIntent().getStringExtra(DataSerciceDetails.EDATE);
        shopId = getIntent().getStringExtra(DataSerciceDetails.SHOP_ID);
        shopTypeId = getIntent().getStringExtra(DataSerciceDetails.SHOPTYPE_ID);
    }

    @Override
    public void initToolBar(TitleBuilder mTitleBuilder) {
        mTitleBuilder.setMiddleTitleText("数据服务")
                .setLeftDrawable(R.mipmap.icon_back)
                .seTitleBgRes(R.mipmap.bg_title)
                .setMiddleTitleTextColor(ContextCompat.getColor(this, R.color.text_white));
    }

    @Override
    public void setupAcitivtyComponent(ApplicationComponent appComponent) {
        DaggerPublicmComponent.builder().applicationComponent(appComponent)
                .publicmModule(new PublicmModule(this))
                .build().inject(this);
    }

    @Override
    public void showLoadding() {

    }

    @Override
    public void dimissLoding() {

    }

    @Override
    public void showErrorMessage(String msg) {

    }

    @Override
    public String getToken() {
        return reqeustUser.getToken();
    }

    @Override
    public String getTypeId() {
        return shopTypeId;
    }

    @Override
    public String getShopId() {
        return shopId;
    }

    @Override
    public String getSdate() {
        return sDate;
    }

    @Override
    public String getEdate() {
        return eDate;
    }

    /**
     * 更新界面商户信息
     *
     * @param shopDetailBaseEntity 商户信息实体
     */
    @Override
    public void updateUI(BaseEntity<ShopDetail> shopDetailBaseEntity) {
        Glide.with(this).load(shopDetailBaseEntity.getData().getShop_pic()).into(mDetails_img);
        mShopName.setText(shopDetailBaseEntity.getData().getShop_name());
        Log.d("DataSerciceDetails", shopDetailBaseEntity.toString());
        mShopDetailList = shopDetailBaseEntity.getData().getShop_list();
        mAdapter.update(mShopDetailList);
    }


}
